rm(list=ls())

source("code/install_Rpackages")
source("code/config.R")

stata_path <- "path_to_stata_executable" # Define the path to your Stata executable

STATA<- function(stata_path) { system(paste(shQuote(stata_path), "-e do", shQuote(stata_script)))}

# STATA build scripts
STATA(paste0(CODE,"0_prepFarecardData.do"))
STATA(paste0(CODE,"1_genLocPairs.do"))
STATA(paste0(CODE,"2_genCardSample.do"))
STATA(paste0(CODE,"3_genHomeWork.do"))
STATA(paste0(CODE,"4_supplementaryData.do"))

# R scripts
source(paste0(CODE,"0_data_build.R"))
source(paste0(CODE,"1_gravity.R"))
source(paste0(CODE,"2_solve_endo.R"))
source(paste0(CODE,"3_parameter_estimation.R"))
source(paste0(CODE,"4_counterfactuals.R"))
source(paste0(CODE,"5_income_map.R"))

# STATA analysis scripts
STATA(paste0(CODE,"1_tripCountsAroundOpening.do"))
STATA(paste0(CODE,"2_tripCountsByDayInPanel.do"))
STATA(paste0(CODE,"3_eventstudy.do"))
STATA(paste0(CODE,"4_scatterplots.do"))